package com.das.mechanic_base.widget;

import android.content.Context;
import android.view.View;
import android.widget.ProgressBar;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.das.mechanic_base.R;
import com.das.mechanic_base.adapter.main.X3CarQuestionAdapter;
import com.das.mechanic_base.base.X3BaseBottomSheetDialog;
import com.das.mechanic_base.bean.main.CarQuestionSelectBean;
import com.das.mechanic_base.bean.main.CrmCarQuetionBean;
import com.umeng.analytics.MobclickAgent;

import java.util.List;

public class X3CarQuestionDialog extends X3BaseBottomSheetDialog implements X3CarQuestionAdapter.IOnCarQuestionListener, View.OnClickListener {

    private RecyclerView recyclerview;
    private X3CarQuestionAdapter carQuestionAdapter;
    private ProgressBar pb_bar;
    private String from;
    private TextView tv_title;
    private TextView tv_cancel;

    public X3CarQuestionDialog(@NonNull Context context, String from) {
        super(context);
        this.from = from;
    }

    @Override
    protected boolean getDialogCancel() {
        return false;
    }

    @Override
    protected void initView() {
        recyclerview = findViewById(R.id.recyclerview);
        recyclerview.setLayoutManager(new LinearLayoutManager(mContext));
        carQuestionAdapter = new X3CarQuestionAdapter(mContext);
        recyclerview.setAdapter(carQuestionAdapter);
        carQuestionAdapter.setiOniOnCarQuestion(this);
        pb_bar = findViewById(R.id.pb_bar);
        tv_title = findViewById(R.id.tv_title);
        tv_cancel = findViewById(R.id.tv_cancel);
        tv_cancel.setOnClickListener(this);
        if(from.equals("1")){//车况问题
            tv_title.setText(mContext.getString(R.string.x3_car_condition_problems));
        }else {//保养计划
            tv_title.setText(mContext.getString(R.string.x3_main_work_plan));
        }
    }

    @Override
    protected int getLayoutId() {
        return R.layout.x3_dialog_carquestion;
    }

    public void changeData(List<CrmCarQuetionBean> crmCarQuetionList,List<CarQuestionSelectBean> selectLists) {
        pb_bar.setVisibility(View.GONE);
        if (carQuestionAdapter == null) {
            return;
        }
        if(crmCarQuetionList == null){
            return;
        }
        carQuestionAdapter.setDataList(crmCarQuetionList,selectLists);

    }

    @Override
    public void show() {
        super.show();
        pb_bar.setVisibility(View.VISIBLE);
    }

    @Override
    public void getCarQuesInfo(CrmCarQuetionBean crmCarQuetionBean) {//点击条目获取选择的车况分类
        if (crmCarQuetionBean == null) {
            return;
        }
        if( iOnCarQuestion !=null ){
            iOnCarQuestion.getCarQuesDialogInfo(crmCarQuetionBean);
        }
    }

    IOnCarQuesDialogListener iOnCarQuestion;

    public void setiOniOnCarQuestion(IOnCarQuesDialogListener iOnCarQuestion) {
        this.iOnCarQuestion = iOnCarQuestion;
    }

    @Override
    public void onClick(View v) {
        if (v.getId() == R.id.tv_cancel) {
            dismiss();
        }
    }

    public interface IOnCarQuesDialogListener {
        void getCarQuesDialogInfo(CrmCarQuetionBean crmCarQuetionBean);
    }
    @Override
    protected void onStart() {
        super.onStart();
        if(from.equals("1")){//车况问题
            tv_title.setText(mContext.getString(R.string.x3_car_condition_problems));
            MobclickAgent.onPageStart("机会列表车况问题筛选弹窗");
        }else {//保养计划
            tv_title.setText(mContext.getString(R.string.x3_main_work_plan));
            MobclickAgent.onPageStart("机会列表保养计划筛选弹窗");
        }

    }

    @Override
    protected void onStop() {
        super.onStop();
        if(from.equals("1")){//车况问题
            tv_title.setText(mContext.getString(R.string.x3_car_condition_problems));
            MobclickAgent.onPageEnd("机会列表车况问题筛选弹窗");
        }else {//保养计划
            tv_title.setText(mContext.getString(R.string.x3_main_work_plan));
            MobclickAgent.onPageEnd("机会列表保养计划筛选弹窗");
        }
    }
}
